/**
 * 1.通过id获取对象
 */
function $(id){
    return document.getElementById(id);
}
/**
 * 2.获取网页传入数据
 */
function getQuery(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}

/**
 *
 */
window.onload=function (){
    fullTable(getQuery("id"));
    getChannel();
    // $("channelDiv").innerHTML=getQuery("name")
}
/**
 *
 */
function fullTable(id){
    axios.get("/topic/findById", {params:{
            // address:$("address").value,
            // status:$("status").value,
            // roomCan:$("roomCan").value,
            // type:$("type22").value
            id
        }}).then(
        resp=>{
            var list= resp.data.list;
            $("topicDiv").innerHTML=resp.data.name;
            $("topicId").value=resp.data.id;
            var info="";
            list.forEach(
                e=>{
                    info+=`<tr>
                    <td>${e.userBean.name}</td><td>${e.title}</td>
                    <td>${e.contents}</td><td>${e.date}</td>
                    </tr>`;
                    $("discussData").innerHTML=info;

                }
            )
        }
    )
}
/**
 *
 */
function submit(){
        axios.get("/discuss/add",{
            params:{
                topicId:$("topicId").value,
                title:$("title").value,
                contents:$("contents").value
            }
        }).then(
            resp=>{
                if(resp.data=="noLogin"){
                    location.href="/html/login.html"
                }
              else if(resp.data=="ok"){
                   fullTable(getQuery("id"))
               }

            }
        )
}

function  getChannel(){
    axios.get("/discuss/getChannel").then(
        resp=>{
           $("channelDiv") .innerHTML=resp.data;
        }
    )
}